import 'package:flutter/material.dart';
import 'package:mpcore/mpkit/mpkit.dart';
import 'package:dio/dio.dart' as dio;
import 'color_constant.dart';
import 'home_content_widget.dart';
import 'icon_config_default.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return HomePageState();
  }
}

class HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
    //requestData();
  }

  @override
  Widget build(BuildContext context) {
    return MPScaffold(
      name: "主页", //页面标题，在浏览器或小程序页面导航栏
      backgroundColor: ColorConstant.ffecf2f3, //导航栏背景色，小程序或浏览器
      body: contentView(),
      floatingBody: Positioned(//自定义浮动元素，必须用Positioned元素包裹
        right: 0,
        bottom: 50,
        child: Container(
          width: 50,
          height: 50,
          color: Colors.red,
        ),
      ),
    );
  }

  void requestData() async {
    final response = await dio.Dio()
        .get("", options: dio.Options(responseType: dio.ResponseType.json));
  }

  contentView() {
    return Stack(
      children: [
        Positioned(
          top: 0,
          left: 0,
          right: 0,
          child: Image.asset(IconAssetsDefault.homeHeadBg,height: 200,fit: BoxFit.contain)
        ),
        Container(
          height: 96,
          alignment: Alignment.bottomLeft,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                width: 120,
                height: 20,
                margin: const EdgeInsets.only(left: 8),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text("永新汇-2楼",style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: 16,
                      color: ColorConstant.ff1d201e
                    ),maxLines: 1,overflow: TextOverflow.ellipsis),
                    Image.asset(IconAssetsDefault.homeLefTopAddressImg,height: 20,fit: BoxFit.contain)
                  ],
                ),
              ),
              Container(
                width: 100,
                height: 30,
                margin: const EdgeInsets.only(right: 16),
                decoration: BoxDecoration(
                  color: ColorConstant.ffffff99,
                  borderRadius: BorderRadius.circular(14),
                  border: Border.all(color: ColorConstant.ff979797,width: 1)
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset(IconAssetsDefault.homeRightScan,height: 30,width:30,fit: BoxFit.contain),
                    Text("扫一扫",style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 14,
                        color: ColorConstant.ff333333
                    ))
                  ],
                ),
              )
            ],
          ),
        ),
        Container(
          padding: const EdgeInsets.only(top: 104),
          child: HomeContentWidget(),
        )
      ],
    );
  }
}
